build: patch TF python_configure to fix genrule toolchain issues #4864
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a workaround for #4862 - see that issue for all the gory details.
The tl;dr is that we want to fix an omission in the TF python configuration rules, where they only list a small number of environment variables that their repository rules are sensitive to. In particular they don't include
PATH(orPYTHONPATHorPYTHONHOME), even though these are all actually used by the toolchain resolution rules to find the active python binary and python lib directory. So we just patch them in, which ameliorates #4862. (In theory we could try to upstream this, but we're currently pinned to TF 2.3.0 rules and having to upgrade will probably be painful.)Tested: ran repro script from #4862 and verified that after this change, while it still bakes the local python path into the py_binary wrapper script that's invoked by the genrule, it at least regenerates the wrapper when
PATHchanges (i.e. when switching virtualenvs) which mostly sidesteps the problem. It would still feel more foolproof to never bake in that path at all and continue using Bazel's autodetecting python toolchain, but to do that I think we might need to migrate off of the TF workspace rules entirely.